package com.eat.fish_service.controller.web;


import com.eat.common_utils.R;
import com.eat.fish_service.entity.Dao.Expert;
import com.eat.fish_service.entity.ExpertCheck;
import com.eat.fish_service.entity.ExpertQuery;
import com.eat.fish_service.service.ExpertCheckService;
import com.eat.fish_service.service.ExpertService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LWB
 * @since 2022-03-21
 */
@RestController
@RequestMapping("/web/expert")
@CrossOrigin
@Api(tags ="web端专家接口")
public class ExpertController {

    @Autowired
    private ExpertService expertService;

    @Autowired
    private ExpertCheckService expertCheckService;

    @ApiOperation(value = "成为专家上传资质二，返回图片路径，添加专家的时候调用")
    @PostMapping("addqualificationOnePic")
    public R addqualificationOnePic(MultipartFile pic){
        return expertService.addqualificationOnePic(pic);
    }

    @ApiOperation(value = "成为专家上传资质三，返回图片路径，添加专家的时候调用")
    @PostMapping("addqualificationTwoPic")
    public R addqualificationTwoPicPic(MultipartFile pic){
        return expertService.addqualificationTwoPic(pic);
    }

    @ApiOperation(value = "web用户发起成为专家表单,id传用户id,id一定要传！")
    @PostMapping("apply")
    public R apply(@RequestBody @ApiParam(name = "expert", value = "专家信息", required = false) ExpertCheck expertCheck){
        return expertCheckService.apply(expertCheck);
    }

    @ApiOperation(value = "用户查询“我的申请”，传用户id即可，因为用户的专家申请表单id和用户id设置为一致")
    @GetMapping("queryMyApply/{id}")
    public R queryMyApply(@PathVariable("id") @ApiParam("用户id") String id){
        return expertCheckService.queryMyApply(id);
    }

    @ApiOperation(value = "管理员查询“审核列表”")
    @GetMapping("queryCheckList")
    public R queryList(){
        return  expertCheckService.queryCheckList();
    }

    @ApiOperation(value = "管理员查询某个审核表单")
    @GetMapping("getOneExpertCheck/{id}")
    public R oneExpertCheck(@PathVariable("id") @ApiParam(value = "要审核的表单id")String id){
        return expertCheckService.getOneExpertCheck(id);
    }

    @ApiOperation(value = "管理员审核专家表单")
    @PostMapping("result/{id}/{isPass}")
    public R result(
            @PathVariable("id")
            @ApiParam(value = "要审核的表单id")        String id,
            @ApiParam(name = "isPass",value = "审核结果，0：未审核；1：通过；2：不通过；管理员只需传1或2表示通过还是不通过")
            @PathVariable("isPass") Integer isPass,
            @RequestBody(required = false)
            @ApiParam(name = "reason",value = "审核不通过才需要填",required = false) String reason){
        return expertCheckService.result(id,isPass,reason);
    }

    //条件查询鱼百科带分页文件数据
    @ApiOperation(value = "web条件查询专家带分页数据")
    @PostMapping("getexpert/{current}/{size}")
    public R pageExpertCondition(@PathVariable
                                    @ApiParam(name = "current", value = "当前页", required = true) Long current,
                                    @PathVariable
                                    @ApiParam(name = "size", value = "每页显示条数", required = true)  Long size,
                                    @RequestBody(required = false)
                                    @ApiParam(name = "ExpertQuery", value = "查询对象条件，专家的介绍和学历模糊查询，专家名字等值查询，时间范围查询", required = false) ExpertQuery expertQuery) {

        return expertService.pageExpertCondition(current, size, expertQuery);
    }

    //根据id查询专家数据
    @ApiOperation(value = "根据id查询专家数据")
    @GetMapping("getExpert/{expertId}")
    public R getExpert(@PathVariable @ApiParam(name = "expertId", value = "专家类Id", required = true) String expertId) {
        return expertService.getExpert(expertId);
    }
}

